﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using SisVenda.Web.messageBox;
using SisVenda.Web.Code;

namespace SisVenda.Web.Administrador
{
	public partial class CadastrarCategoriaVenda : System.Web.UI.Page
	{
		protected void Page_Load(object sender, EventArgs e)
		{
            MessageBox.Include(this);
		}

        protected void btnPesquisar_Click(object sender, EventArgs e)
        {
            gvwListagem.DataBind();
        }

        protected void ddlNumeroLinhasGrid_SelectedIndexChanged(object sender, EventArgs e)
        {
            gvwListagem.DataBind();
        }

        protected void gvwListagem_DataBinding(object sender, EventArgs e)
        {
            gvwListagem.PageSize = Convert.ToInt16(ddlNumeroLinhasGrid.SelectedValue);
        }

        protected void gvwListagem_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (fvwEdicao.CurrentMode != FormViewMode.ReadOnly)
                fvwEdicao.ChangeMode(FormViewMode.ReadOnly);
            fvwEdicao.DataBind();
        }

        protected void oldGridViewCatVenda_Selecting(object sender, ObjectDataSourceSelectingEventArgs e)
        {
            if (tbxDescricao.Text != "")
                e.InputParameters["descricao"] = tbxDescricao.Text;
        }

        protected void odsFormViewCatVenda_Deleted(object sender, ObjectDataSourceStatusEventArgs e)
        {
            gvwListagem.DataBind();
        }

        protected void odsFormViewCatVenda_Deleting(object sender, ObjectDataSourceMethodEventArgs e)
        {
            Label id_catVen = (Label)fvwEdicao.FindControl("lblCodigo");

            if (gvwListagem.SelectedDataKey != null)
                e.InputParameters["idCategoriaVenda"] = gvwListagem.SelectedDataKey.Value;
            else
                e.InputParameters["idCategoriaVenda"] = id_catVen.Text;
            id_catVen.Dispose();
        }

        protected void odsFormViewCatVenda_Inserted(object sender, ObjectDataSourceStatusEventArgs e)
        {
            gvwListagem.DataBind();
        }

        protected void odsFormViewCatVenda_Selecting(object sender, ObjectDataSourceSelectingEventArgs e)
        {
            if (gvwListagem.SelectedDataKey != null)
            {
                e.InputParameters["idCategoriaVenda"] = gvwListagem.SelectedDataKey.Value;
            }
        }

        protected void odsFormViewCatVenda_Updated(object sender, ObjectDataSourceStatusEventArgs e)
        {
            gvwListagem.DataBind();
        }

        protected void odsFormViewCatVenda_Updating(object sender, ObjectDataSourceMethodEventArgs e)
        {
            Label id_catVen = (Label)fvwEdicao.FindControl("lblCodigoUp");
            TextBox desc = (TextBox)fvwEdicao.FindControl("tbxDescricaoUp");

            if (gvwListagem.SelectedDataKey != null)
                e.InputParameters["idCategoriaVenda"] = gvwListagem.SelectedDataKey.Value;
            else
                e.InputParameters["idCategoriaVenda"] = id_catVen.Text;
            e.InputParameters["descricao"] = desc.Text;

            id_catVen.Dispose();
            desc.Dispose();
        }

        protected void odsGridViewCatVenda_Selecting(object sender, ObjectDataSourceSelectingEventArgs e)
        {
            if (tbxDescricao.Text != "")
                e.InputParameters["descricao"] = tbxDescricao.Text;
        }

	}
}